package cn.xspace.module.other.http.impl;

import java.util.List;

import com.xspace.android.xafcommon.network.NetConstant;
import com.xspace.android.xafcommon.network.message.AResponseMsg;
import com.xspace.android.xafcommon.network.message.SendRequestListener;

import android.app.Activity;
import android.widget.Toast;
import cn.xspace.module.other.bean.PlaceSetBean;
import cn.xspace.module.other.http.NetControl;
import cn.xspace.module.other.http.intface.IPlaceMg;
import cn.xspace.module.other.http.resp.PlaceSetResp;
import cn.xspace.module.other.util.RProxy;

/**
 * @ClassName: PlaceManage
 * @author:guankui
 * @Date：2014年2月21日
 * @version V1.0.0
 * @Description: 获取地区接口实现类
 */
public class PlaceSetMgImpl implements IPlaceMg, SendRequestListener {

	private NetControl mNetControl;
	private Activity mContext;
	private IPlaceSetRequest mCallBack;

	public PlaceSetMgImpl(Activity mContext) {
		this.mContext = mContext;
		mNetControl = new NetControl(this);
	}

	@Override
	public void placeRequest(String areacode, IPlaceSetRequest mCallBack) {
		this.mCallBack = mCallBack;
		sendPlaceRequest(areacode);
	}

	@Override
	public void sendPlaceRequest(String areacode) {
		mNetControl.sendPlaceRequest(areacode);
	}

	@Override
	public void requestResult(int result, AResponseMsg object) {
		if (NetControl.MSGTYPE_PLACE_SET.equals(object.msgType)) {
			PlaceSetResp resp = (PlaceSetResp) object;
			if (result == NetConstant.TaskStatus.SUCCESS&&resp.code.equals("0")) {
				mCallBack.onResult(resp.mList);
			} else {
				Toast.makeText(mContext, RProxy.network_fail,
						Toast.LENGTH_SHORT).show();
				mCallBack.onResult(null);
			}
		}

	}

	@Override
	public void offline(String msgType) {
		Toast.makeText(mContext, RProxy.network_fail, Toast.LENGTH_SHORT)
				.show();
		mCallBack.onResult(null);
	}

	public interface IPlaceSetRequest {
		public void onResult(List<PlaceSetBean> returnList);
	}

}
